﻿/// <reference path="duomi.common.ajax.js" />
/*************************************************************
Base Common Remote Ajax Js.
远程(跨域)Ajax请求
Create By Ming.ma
2014-08-06 V1.0
*************************************************************/
Namespace.register("$ext.remote.majax");

(function () {
    $ext.remote.majax = {
        $description: '远程(跨域)Ajax请求',
        $author: 'Ming.ma',
        $version: '1.0.0',
        ajax: function (option) { return ajax(option); }
    };
    var $handlerPath = "/common/CommonHandler.ashx?action=GETREMOTEURLTEXT";

    var defaultOption = {
        url: '',
        data: '',
        type: 'get',
        encoding: 'UTF-8',
        async: true,
        success: {},
        error: {}
    };

    function ajax(option) {
        debugger;
        var _option = leftCopyJson(defaultOption, option);
        $ajax.ajax({ url: $handlerPath + bulidParams(_option), type: 'get', success: function (t) { option.success(t); }, error: function (e) { option.error(t); } });
    }


    function bulidParams(option) {
        return '&type=' + option.type + //请求类型
            '&encoding=' + option.encoding +//请求编码类型
            '&remoteUrl=' + encodeURIComponent(option.url) + //远程地址
            '&data=' + encodeURIComponent(option.data); //请求时参数
    }

    function leftCopyJson(jsn1, jsn2) {
        var jsn = {};
        for (var j in jsn1) {
            jsn[j] = $object.isNull(jsn2[j]) ? jsn1[j] : jsn2[j];
        }
        return jsn;
    }

})();